package com.nursing.Dao;

import com.nursing.bean.HealthRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HealthRecordDao {
    @Select("SELECT * FROM health_record")
    List<HealthRecord> getAll();

    @Select("SELECT * FROM health_record WHERE id = #{id}")
    HealthRecord getById(Integer id);

    @Select("SELECT * FROM health_record WHERE elder_id = #{elderId}")
    HealthRecord getByElderId(Integer elderId);

    @Insert("INSERT INTO health_record (elder_id, medical_history, allergy, medication, checkup_data) " +
            "VALUES (#{elderId}, #{medicalHistory}, #{allergy}, #{medication}, #{checkupData})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(HealthRecord healthRecord);

    @Update("UPDATE health_record SET medical_history = #{medicalHistory}, allergy = #{allergy}, " +
            "medication = #{medication}, checkup_data = #{checkupData} WHERE id = #{id}")
    void update(HealthRecord healthRecord);

    @Delete("DELETE FROM health_record WHERE id = #{id}")
    void delete(Integer id);
}